共计 1143 个字符,预计需要花费 3 分钟才能阅读完成。
update-alternatives
update-alternatives 是 Ubuntu 系统下命令行软件多版本管理工具。
以“JDK”多版本管理为例:
安装 openJDK17
sudo apt install openjdk-17-jdk
安装 openJDK1.8
sudo apt install openjdk-8-jdk
查看当前“JDK”版本
> $ java --version
openjdk 17.0.10 2024-01-16
OpenJDK Runtime Environment (build 17.0.10+7-Ubuntu-120.04.1)
OpenJDK 64-Bit Server VM (build 17.0.10+7-Ubuntu-120.04.1, mixed mode, sharing)
yinhn@XYZ
update-alternatives –config 切换“JDK”版本
> $ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 auto mode
1 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
yinhn@XYZ
再次查看“JDK”版本
> $ java -version
openjdk version "1.8.0_402"
OpenJDK Runtime Environment (build 1.8.0_402-8u402-ga-2ubuntu1~20.04-b06)
OpenJDK 64-Bit Server VM (build 25.402-b06, mixed mode)
yinhn@XYZ
此时“JDK”版本已经完整从 17 切换为 1.8 版本,“javac”同理也可切换,其他软件亦是如此。
正文完